<template>
  <div @keyup.enter="getData()">
    <el-form class="query-table-form" :inline="true">
      <el-form-item>
        <el-input v-model="params.customer_name" placeholder="主体名称查询" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="params.corp_name" placeholder="负责人查询" :clearable="true"></el-input>
      </el-form-item>
      <el-form-item>
        <select-address
          v-model="params.address_code"
          clearable
          placeholder="地址查询"
          :auto-top="true"
          @change="getData()"
        ></select-address>
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-search" @click="getData()">查询</el-button>
      </el-form-item>
      <el-form-item>
        <el-button
          icon="el-icon-download"
          :loading="exportLoading"
          @click="exportExcel('项目调查（已拒绝）')"
        >
          导出
        </el-button>
      </el-form-item>
    </el-form>

    <c-table border v-loading="loading" :columns="tableColumns" :data="tableData">
      <template v-slot:address="scope">
        <div class="text-truncate" :title="scope.row.address">{{ scope.row.address }}</div>
      </template>
      <template v-slot:confuseDes="scope">
        <div :title="scope.row.confuse_des">
          {{ scope.row.confuse_des | substr }}
        </div>
      </template>
    </c-table>

    <div class="query-pagination">
      <div></div>
      <el-pagination
        layout="total, prev, pager, next, jumper"
        :current-page.sync="params.index"
        :page-size="params.size"
        :total="totalCount"
        @current-change="getData"
      ></el-pagination>
    </div>

    <el-dialog
      :visible.sync="reportVisible"
      :close-on-click-modal="false"
      append-to-body
      top="30px"
      width="80%"
    >
      <el-tabs v-model="active">
        <el-tab-pane label="项目审批表" name="first">
          <investigate-approve-view
            :query-id="queryId"
            :process-status="relatedData.process_status"
          ></investigate-approve-view>
        </el-tab-pane>
        <!-- <el-tab-pane label="立项附件">
          <item-attach :related-data="relatedData"></item-attach>
        </el-tab-pane> -->
        <el-tab-pane label="担保意向函" name="letter" v-if="+relatedData.ele_letter_status > 0">
          <letter-view :query-id="queryId"></letter-view>
        </el-tab-pane>

        <el-tab-pane label="附件">
          <attach-view :query-id="queryId" :visible="reportVisible"></attach-view>
        </el-tab-pane>
      </el-tabs>
    </el-dialog>

    <attach-cmpt :visible.sync="attachVisible" :customer-related-id="attachRelatedId"></attach-cmpt>

    <reject-view :visible.sync="rejectVisible" :reject-data="rejectRow"></reject-view>
  </div>
</template>

<script>
import { enumGuatype, enumProcessStatus } from '@/credit/plugins/enumTown'

import SelectAddress from '@/components/select/SelectAddress'
import AttachView from '@/credit/components/AttachView'
import AttachCmpt from '@/credit/views/city/program/Attach'
import RejectView from '@/credit/views/city/program/RejectView'

import taskTableMixin from '@/credit/mixin/taskTableCountyUnionProvince'
import LetterView from '@/credit/views/county/unionProvince/components/LetterView'
// import ItemAttach from '@/credit/views/county/unionProvince/components/ItemAttach'
import InvestigateApproveView from '@/credit/views/county/unionProvince/components/InvestigateApproveView'
export default {
  components: {
    SelectAddress,
    AttachView,
    AttachCmpt,
    RejectView,
    LetterView,
    // ItemAttach,
    InvestigateApproveView,
  },
  mixins: [taskTableMixin],
  data() {
    return {
      enumGuatype,
      // enumProjectResStatus,
      order: {
        approved_date: 'desc',
      },
      params: {
        index: 1,
        size: 15,
        address_code: '',
        customer_name: '',
        corp_name: '',
        'confuse_status.eq': 3,
        'item_status.eq': 1,
        'contract_approval_status.lt': 1,
      },

      tableData: [],
      tableColumns: [
        {
          attrs: { label: '客户名称', prop: 'customer_name', minWidth: '110px' },
          process: (v, row) => ({
            attrs: { class: 'project-history', attrs: { 'data-history': row.is_history } },
          }),
        },
        { attrs: { label: '业务类型', prop: 'guaType', align: 'center' } },
        { attrs: { label: '地址', prop: 'address' }, slot: 'address' },
        { attrs: { label: '负责人', prop: 'corp_name', align: 'center' } },
        { attrs: { label: '联系电话', prop: 'mobile_no', align: 'center', width: 120 } },
        { attrs: { label: '申请金额(万元)', prop: 'apply_funds', align: 'center' } },
        { attrs: { label: '拒绝时间', prop: 'confuse_time', width: 140 } },
        {
          attrs: { label: '合作银行', prop: 'bank_name', align: 'center' },
          process: v => v || '-',
        },
        { attrs: { label: '审批模式', prop: 'processLabel', width: 80, align: 'center' } },

        { attrs: { label: '拒绝理由', prop: 'confuse_des' }, slot: 'confuseDes' },
        {
          attrs: { label: '拒绝角色', prop: 'confuse_person', align: 'center' },
          process: v => v || '-',
        },
        {
          attrs: { label: '操作', align: 'center', width: 150 },
          operations: [
            { content: '拒绝详情', icon: 'fa fa-times-circle-o', event: this.handleRejectView },
            // { content: '上传附件', icon: 'fa fa-clipboard', event: this.hanleAttach },
            { content: '查看', icon: 'fa fa-search', event: this.handleView },
          ],
        },
      ],

      rejectRow: {},
      rejectVisible: false,

      reportVisible: false,
      relatedData: {},
      attachVisible: false,
      attachRelatedId: '',
      queryId: '',
      active: 'first',
    }
  },
  computed: {},
  watch: {},
  mounted() {},
  created() {
    this.getData()
  },
  methods: {
    dataAdapter(item) {
      item.guaType = enumGuatype[item.gua_type]
      item.confuse_time = this.$utils.dateFormat(item.confuse_time, this.dateFmt)

      item.processLabel = enumProcessStatus[item.process_status] || ''
      return item
    },
    handleRejectView(row) {
      this.rejectRow = { ...row }
      this.rejectVisible = true
    },
    hanleAttach(row) {
      this.attachVisible = true
      this.attachRelatedId = row.customer_related_id
    },
    handleView(row) {
      this.active = 'first'
      this.queryId = row.customer_related_id
      this.relatedData = row
      this.reportVisible = true
    },
  },
}
</script>
<style lang="scss" scoped>
.status-label {
  display: inline-block;
  padding: 0.25em 0.4em;
  font-size: 75%;
  font-weight: 700;
  line-height: 1;
  text-align: center;
  vertical-align: baseline;
  border-radius: 0.25rem;
  transition: color 0.15s;
}
</style>
